package com.example.administrator.helloword.ui;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.helloword.R;

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText nameEdit;

    private EditText passwordEdit;

    private Button loginBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        nameEdit = findViewById(R.id.nameEdit);
        passwordEdit = findViewById(R.id.passwordEdit);
        findViewById(R.id.loginBtn).setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
//
//        Intent intent = new Intent(this,MainActivity.class);
//        intent.putExtra("name",nameEdit.getText().toString().trim());
//        intent.putExtra("pass",passwordEdit.getText().toString().trim());
//        startActivity(intent);


        if (TextUtils.isEmpty( nameEdit.getText().toString().trim())){
            Toast.makeText(this, "请输入用户名", Toast.LENGTH_SHORT).show();
        }else if(TextUtils.isEmpty( passwordEdit.getText().toString().trim())){
            Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
        }else {
            if (nameEdit.getText().toString().trim().equals("admin") &&passwordEdit.getText().toString().trim().equals("123456")  ){
                startActivity(
                        new Intent(this,MainActivity.class)
                );
            }else {
                Toast.makeText(this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
